﻿/*
	@author : "likaituan",
	@email : "61114579@qq.com",
	@version : "4.0",
	@date : "2010-09-05",
	@lastime : "2011-8-18"
*/


~function(F){
	//媒体播放类
	F.player = {
		//初始化
		init : function (obj,w,h){
			this.box = F(obj) || F().append("div");
			this.w=w||0;
			this.h=h||0;
			this.mp = {};
			this.mplist = [this.wmp, this.rmp];
			this.idlist = ["6bf52a52-394a-11d3-b153-00c04f79faa6","CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"];
			this.typeList = ["application/x-mplayer2", "audio/x-pn-realaudio-plugin"];
			this.statelist = ["初始停止暂停播放搜索搜索缓冲等待结束连接停止".match(/../g)];
			this.statelist[1] = "停止连接缓冲播放暂停搜索".match(/../g);
		},
		//window media player方法
		wmp : {
			play : function(){ F.player.obj.controls.play() },
			pause : function(){ F.player.obj.controls.pause() },
			stop : function(){ F.player.obj.controls.stop() },
			seturl : function(u){ F.player.obj.url = u },
			setpos : function(n){ F.player.obj.controls.currentPosition=n/1000 },
			setvol : function(n){ F.player.obj.settings.volume=n||me.vol },
			setmute : function(){ F.player.obj.settings.mute=!F.player.obj.settings.mute },
			getpos : function(){ return F.player.obj.controls.currentPosition*1000 },
			getlen : function(){ return (F.player.obj.currentMedia||{duration:300}).duration*1000 },
			getstate : function(){ return F.player.statelist[0][F.player.obj.playState] },
			getauthor : function(){ return F.player.obj.currentMedia.getItemInfo("author") },
			gettitle : function(){ return F.player.obj.currentMedia.getItemInfo("title") }
		},
		//realplayer方法
		rmp : {
			play : function(){ F.player.obj.DoPlay() },
			pause : function(){ F.player.obj.DoPause() },
			stop : function(){ F.player.obj.DoStop() },
			seturl : function(u){ F.player.obj.SetSource(u) },
			setpos : function(n){ F.player.obj.setPosition(n) },
			setvol : function(n){ F.player.obj.setVolume(n) },
			setmute : function(){ F.player.obj.setMute(!F.player.obj.getMute()) },
			getpos : function(){ return F.player.obj.GetPosition() },
			getlen : function(){ return F.player.obj.getLength() },
			getstate : function (){ return F.player.statelist[1][F.player.obj.getPlayState()] }
		},
		//打开MP3文件
		open : function(u){
			this.box.html(this.getHTML(u));
			this.obj = this.box.node.firstChild;
			this.obj.uiMode = "None";
			var i = +/\.(?:rm|rmvb|avi)$/.test(u);
			this.mp = this.mplist[i];
			this.mp.seturl(u);
			this.mp.play();
		},
		//获取播放器HTML代码
		getHTML : function(u){
			var i = +/\.(?:rm|rmvb|avi)$/.test(u);
			if (F.isie){
				return '<object classid="clsid:'+this.idlist[i]+'" width="'+this.w+'" height="'+this.h+'"></object>';
			}
			return '<embed type="'+this.typeList[i]+'" src="'+u+'" width="'+this.w+'" height="'+this.h+'"></embed>';
		}
	}
}($1stjs);